package pl.edu.utp.kursy.database.dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import pl.edu.utp.kursy.database.CourseEventCompanyAccomodation;

public class CourseEventCompanyAccomodationDao extends BaseDao<CourseEventCompanyAccomodation>{
    
    public CourseEventCompanyAccomodationDao(SessionFactory sessionFactory){
        super(sessionFactory);
    }
    
    @Override
    public CourseEventCompanyAccomodation getById(int id) {
   Session session = sessionFactory.openSession();
        
        Criteria c = session.createCriteria(CourseEventCompanyAccomodation.class);
        c.add(Restrictions.eq("id", id));    		    		
        CourseEventCompanyAccomodation course = (CourseEventCompanyAccomodation)c.uniqueResult();
        
        session.close(); 
        return course;
    }

    @Override
    public List<CourseEventCompanyAccomodation> getAll() {
        ArrayList<CourseEventCompanyAccomodation> courses;
        
        Session session = sessionFactory.openSession();
        Criteria c = session.createCriteria(CourseEventCompanyAccomodation.class);
        c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        courses = (ArrayList<CourseEventCompanyAccomodation>)c.list();
        session.close();
        return courses;  
    }
    
}
